home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- #include "werr.h"
- #include "global.h"
- #include "mbuf.h"
- #include "internet.h"
- #include "iface.h"
- #include "cmdparse.h"
- #include "misc.h"
- #include "asy.h"
- #include "slip.h"
- #include "arc.h"
- #include "os.h"
- #include "swis.h"
-
- struct asy asy[ASY_MAX];
- unsigned int nasy;
- extern struct interface *ifaces;
-
- extern char nospace[];
-
- static int asy_init(int16, struct interface *, int);
- static int asy_stop(struct interface *);
- static int asy_speed(int16, int);
- static int asy_output(int16, char *, int);
- static int asy_recv(int16, char *, int);
-
- /* Attach a serial interface to the system
- * argv[0]: hardware type, must be "asy"
- * argv[1]: async driver name, must be "internal"
- * argv[2]: port number, must "0"
- * argv[3]: mode, may be:
- * "slip" (point-to-point SLIP)
- * argv[4]: interface label, e.g., "sl0"
- * argv[5]: maximum transmission unit, bytes
- * argv[6]: interface speed, e.g, "9600"
- */
- int asy_attach(int argc, char **argv)
- {
- struct interface *if_asy;
- struct slip *if_slip;
- int16 dev;
- int mode;
-
- argc = argc;
-
- if (nasy >= ASY_MAX) {
- werr(1, "Too many async controllers");
- return -1;
- }
-
- if (strcmp(argv[1], "internal") != 0) {
- werr(1, "Unknown serial port %s", argv[1]);
- return -1;
- }
-
- if (strcmp(argv[2], "0") != 0) {
- werr(1, "Unknown serial port %s", argv[2]);
- return -1;
- }
-
- if (strcmp(argv[3],"slip") == 0)
- mode = SLIP_MODE;
- else
- mode = UNKNOWN;
-
- dev = nasy++;
-
- /* Create interface structure and fill in details */
- if_asy = (struct interface *)calloc(1,sizeof(struct interface));
-
- if_asy->name = strdup(argv[4]);
- if_asy->mtu = atoi(argv[5]);
- if_asy->dev = dev;
- if_asy->recv = doslip;
- if_asy->stop = asy_stop;
- if_asy->put = asy_output;
- if_asy->get = asy_recv;
-
- switch(mode){
- case SLIP_MODE:
- if_slip = (struct slip *)calloc(1,sizeof(struct slip));
- if_asy->slip = if_slip;
- if_asy->send = slip_send;
- if_asy->raw = slip_raw;
- if_asy->slip->recv = slip_recv;
- break;
- default:
- werr(1, "Mode %s unknown for interface %s", argv[3], argv[4]);
- free(if_asy->name);
- free(if_asy);
- nasy--;
- return -1;
- }
-
- if_asy->next = ifaces;
- ifaces = if_asy;
- asy_init(dev, if_asy, atoi(argv[2]));
- asy_speed(dev, atoi(argv[6]));
- return 0;
- }
-
- /* Initialize asynch port "dev" */
- static int asy_init(int16 dev, struct interface *iface, int port)
- {
- os_regset regs;
-
- asy[dev].iface = iface;
- asy[dev].port = port;
- asy[dev].speed = 0;
-
- /* Start up serial interrupts */
- regs.r[0] = 2;
- regs.r[1] = 2;
- os_swix(OS_Byte, ®s);
-
- regs.r[0] = 1;
- regs.r[1] = 0x00;
- os_swix(OS_SerialOp, ®s);
-
- return(1);
- }
-
- static int asy_stop(struct interface *interface)
- {
- os_regset regs;
-
- interface = interface;
-
- /* Stop serial interrupts */
- regs.r[0] = 2;
- regs.r[1] = 0;
- os_swix(OS_Byte, ®s);
-
- return(0);
- }
-
- static struct
- {
- int real_speed;
- int arc_speed;
- }
- speed_table[] =
- {
- {300, 3},
- {1200, 4},
- {2400, 5},
- {4800, 6},
- {9600, 7},
- {19200, 8}
- };
-
- #define ARC_SPEED_COUNT 6
-
- /* Set asynch line speed */
- static int asy_speed(int16 dev, int speed)
- {
- os_regset regs;
- int i;
-
- if (speed == 0 || dev >= nasy) return(-1);
-
- for (i = 0; i < ARC_SPEED_COUNT; i++)
- {
- if (speed_table[i].real_speed == speed)
- {
- asy[dev].speed = speed;
-
- regs.r[0] = 5;
- regs.r[1] = speed_table[i].arc_speed;
- os_swix(OS_SerialOp, ®s);
-
- regs.r[0] = 6;
- regs.r[1] = speed_table[i].arc_speed;
- os_swix(OS_SerialOp, ®s);
-
- return(0);
- }
- }
-
-
- werr(0, "Invalid speed %d", speed);
-
- return(-1);
- }
-
- /* Send a buffer to serial transmitter */
- static int asy_output(int16 dev, char *buf, int cnt)
- {
- register int i;
-
- if (dev >= nasy) return(0);
-
- for (i = 0; i < cnt && ser_putc(*buf) != 0; i++, buf++);
-
- return(i);
- }
-
- /* Receive characters from asynch line
- * Returns count of characters read
- */
- static int asy_recv(int16 dev, char *buf, int cnt)
- {
- if (dev >= nasy || cnt < 1) return(0);
-
- return((ser_getc(buf) != 0) ? 1 : 0);
- }
-
-
-